﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace WebArchiveCopier
{
	public class WebArchive
	{
		public static string ItemListAddressFormat = "http://wayback.archive.org/web/*/{0}*";
		public static string ItemCaptureCalendarAddressFormat = "http://wayback.archive.org/web/*/{0}";
		public static string ItemCaptureCalendarByDateAddressFormat = "http://web.archive.org/web/{0}*/{1}";

		internal static List<String> ItemCaptureAddressFormats = InitItemCaptureAddressFormats();

		private static List<String> InitItemCaptureAddressFormats()
		{
			var list = new List<string>();
			list.Add("http://web.archive.org/web/{0}id_/{1}");
			list.Add("http://web.archive.bibalex.org/web/{0}id_/{1}");
			return list;
		}

		public static string GetItemListAddress(string address)
		{
			return string.Format(ItemListAddressFormat, address);
		}

		public static string GetItemCaptureCalendarAddress(string address)
		{
			return string.Format(ItemCaptureCalendarAddressFormat, address);
		}

		public static string GetItemCaptureCalendarAddress(string address, string year)
		{
			return string.Format(ItemCaptureCalendarByDateAddressFormat, year, address);
		}

		public static IEnumerable<string> GetItemCaptureAddresses(string address, DateTime date)
		{
			foreach (var format in ItemCaptureAddressFormats)
			{
				yield return string.Format(format, date.ToString("yyyyMMddHHmmss"), address);
			}
		}
	}
}
